﻿using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace Medhurst.Unity.Configuration
{
    public static class UnityContainerExtensions
    {
        public static IUnityContainer LoadConfigurationFromYaml(this IUnityContainer unity)
        {
            var aliasPath = ConfigurationManager.AppSettings["Unity.YAML.Paths.AssemblyDeclarations"];
            var behavioursPath = ConfigurationManager.AppSettings["Unity.YAML.Paths.BehaviourDeclarations"];
            return unity.LoadConfigurationFromYaml(aliasPath, behavioursPath);
        }

        public static IUnityContainer LoadConfigurationFromYaml(this IUnityContainer unity, string aliasPath, string behavioursPath)
        {
            new YamlConfigLoadFactory()
                .WithFileNames(aliasPath, behavioursPath)
                .LoadFromFiles()
                .ProcessBehaviours(unity);

            return unity;
        }
    }
}
